/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import bo.Etoile;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author amine.tayaa
 */
public class DaoEtoile {
    
    static PreparedStatement ps=null;
    static ResultSet rs;
    static SqlConnect connexion=null;
    
    
    
    public static Vector<Etoile> getEtoileList()
    {
        Vector<Etoile> vEtoile=new Vector<Etoile>();
        try {
            ps=connexion.connectMysql().prepareStatement("select * from etoile");
            rs=ps.executeQuery();
            ps.clearParameters();
            
            while((rs.next()) && (rs.getRow()<50))
            {
                vEtoile.add(new Etoile(rs.getString(1),rs.getDouble(2),rs.getDouble(3),rs.getString(4)));
                
            }
    
        } catch (SQLException ex) {
            Logger.getLogger(DaoEtoile.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return vEtoile;
    }
    
    public static Etoile getEtoile_Nom(String Nom)
    {
        Etoile e=null;
        try {
            ps=connexion.connectMysql().prepareStatement("select * from etoile where nom=?");
            ps.setString(1, Nom);
            rs=ps.executeQuery();
            ps.clearParameters();
            
            while(rs.next())
            {
                e=new Etoile(rs.getString(1),rs.getDouble(2),rs.getDouble(3),rs.getString(4));
                
            }
    
        } catch (SQLException ex) {
            Logger.getLogger(DaoEtoile.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        return e;
        
    }
    
    
    public static Vector<Etoile> getEtoile_Coord(double ascension,double declinaison)
    {
        Vector<Etoile> vEtoileCoord=null;
         try {
            ps=connexion.connectMysql().prepareStatement("select * from etoile where ascension_droite=? and declinaison=?");
            ps.setDouble(1, ascension);
            ps.setDouble(2, declinaison);
            rs=ps.executeQuery();
            ps.clearParameters();
            
            while(rs.next())
            {
                vEtoileCoord.add(new Etoile(rs.getString(1),rs.getDouble(2),rs.getDouble(3),rs.getString(4)));
                
            }
    
        } catch (SQLException ex) {
            Logger.getLogger(DaoEtoile.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        return vEtoileCoord;
    }
    
    
    
    
    
    
}
